<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="../main.css" >
        
        <title>Functions</title>
    </head>

    <body>
        <h1 class="sub_title">Functions</h1>

        <p>Functions are used to group together code that performs a certain task.  For example a function
            could be created that prints the values of an array to the terminal.  This way you would
            not have to write the same code over and over and have it take up so much space.  Every program
            PET has at least one function, the main function.  Main is the function that gets called to
            start your programs execution, but you can also define functions of your own and call them as you
            please.  A function name must follow the same rules as a variable name, it can only contain
            uppercase letters, lowercase letters, and the underscore symbol (_).  Also you can not use 
            any PET keywords such as if or while as a function name.  For a list of keywords that can not be
            used as names see the keywords page in the section of the user manual. </p>
            
            <p>Functions are defined using the following syntax: define name { ... }
                <br> Here ... must represent at least one new line character.</p>
                
            <p>Functions are called using the call command.  Calling a function will cause execution to go
                to that function and will continue on the next line when that function has completed.</p>

        <h1 class="special">Code:</h1>
        <pre class="code">
array a[2]

define main {

    a[0] = 2
    a[1] = 5
    
    # a function call
    call reset_array
    
    write a[0] a[1]

}

# a function definition
define reset_array {
    a[0] = 0
    a[1] = 0
    
}</pre>

    </body>
</html>
    
